import Vue from 'vue'
import Vuex from 'vuex'


//1、安装插件
Vue.use(Vuex)

//2、创建对象
const store = new Vuex.Store({
    state: {
        counter: 100,
        students: [
            { id: 1, name: '李民康', age: 18 },
            { id: 2, name: '李民辉', age: 23 },
            { id: 3, name: '李民健', age: 18 },
            { id: 4, name: '李民祥', age: 22 },
        ],
        info: {
            name: '孤鸿寄语丨默苍离',
            sex: '男',
            age: 43
        }
    },
    mutations: {
        increment(state) {
            state.counter++;
        },
        decrement(state) {
            state.counter--;
        }
    },
    actions: {},
    getters: {
        powerCounter(state) {
            return state.counter * state.counter
        },
        getSomeStudent(state) {
            return state.students.filter(s => {
                return s.age > 18;
            })
        },
        getStudentsCount(state, getters) {
            return getters.getSomeStudent.length
        },
        getStudentsByAge(state) {
            return function(age) {
                return state.students.filter(s => {
                    return s.age > age
                })
            }
        }
    },
    modules: {},

})

//3、到处store对象
export default store